<input type="hidden" id="desc_status" value="<?php echo $this->session->flashdata('photo_edit_status'); ?>" />
<script type="text/javascript">
  $(document).ready(function() {
    $('#comment_message').wysihtml5();
    var desc_status = $.trim($('#desc_status').val());
    if (desc_status == 1) {
      toastr.success('Successfully saved description');
    }
    if (desc_status == 2) {
      toastr.error('Error occured. Try again !');
    }
    load_new_comments(true);
    update_likes_count();
  });
</script>
<?php $get_user_like_status = get_user_like_status('photo', $photo_data['photo_id']); ?>
<div class="page" style="min-height: 500px;">
  <div class="page-container">
    <div class="container">
      <div class="row">
        <div class="span12 header" id="nav">
          <div class="btn-group pull-right">
            <?php if ($prev_id) { ?>
              <?php if ($prev_type == 1) { ?>
                <input type="hidden" id="prev_photo_id" value="<?php echo (base_url('album/photo/' . $prev_id . '#nav')); ?>"/>
                <a href="<?php echo base_url('album/photo/' . $prev_id . '#nav'); ?>" class="btn"><< Prev</a>
              <?php } ?>
              <?php if ($prev_type == 2) { ?>
                <input type="hidden" id="prev_photo_id" value="<?php echo (base_url('album/video/' . $prev_id . '#nav')); ?>"/>
                <a href="<?php echo base_url('album/video/' . $prev_id . '#nav'); ?>" class="btn"><< Prev</a>
              <?php } ?>
            <?php } ?>
            <?php if ($next_id) { ?>
              <?php if ($next_type == 1) { ?>
                <input type="hidden" id="next_photo_id" value="<?php echo (base_url('album/photo/' . $next_id . '#nav')); ?>"/>
                <a href="<?php echo base_url('album/photo/' . $next_id . '#nav'); ?>" class="btn">Next >></a>
              <?php } ?>
              <?php if ($next_type == 2) { ?>
                <input type="hidden" id="next_photo_id" value="<?php echo (base_url('album/video/' . $next_id . '#nav')); ?>"/>
                <a href="<?php echo base_url('album/video/' . $next_id . '#nav'); ?>" class="btn">Next >></a>
              <?php } ?>
            <?php } ?>
          </div>
          <div class="btn-group pull-right">
            <a href="<?php echo base_url('album/' . $photo_data['album_id']); ?>" class="btn">View Album</a>
          </div>
          <h4>Photo : <?php echo $photo_data['album_name']; ?></h4>
        </div>
        <div id="photo_image" class="span3">
          <div class="filters">
            <span class="pull-right">
              <a title="<?php echo '@' . $photo_data['user_name']; ?>" style="text-decoration: none; color: #999999;" href="<?php echo base_url('profile/' . $photo_data['user_name']); ?>"><?php echo $photo_data['user_display_name']; ?></a>
            </span>
            <label for="cb3">Uploaded by</label>
            <span class="pull-right"><?php echo date('d-m-Y', strtotime($photo_data['album_date'])); ?></span>
            <label for="cb3">Date</label>
            <span class="pull-right"><?php echo $get_user_like_status['total_count']; ?></span>
            <label for="cb3">Likes</label>
            <span class="pull-right"><?php echo $total_comments_count; ?></span>
            <label for="cb3">Comments</label>
            <?php if (($photo_data['user_id'] == $this->current_user['user_id']) || ($this->is_admin)) { ?>
              <?php if (!empty($photo_data['photo_desc'])) { ?>
                <h5><a style="text-decoration: none; color: #555; font-weight: bold;">Description</a><a id="desc_edit_btn" style="float: right; text-decoration: none; cursor: pointer;" onclick="javascript: $('#desc_form').fadeIn();
                        $('#desc_edit_btn').fadeOut();">Edit</a></h5>
                <?php } else { ?>
                <h5><a style="text-decoration: none; color: #555; font-weight: bold;">Description</a><a id="desc_edit_btn" style="float: right; text-decoration: none; cursor: pointer;" onclick="javascript: $('#desc_form').fadeIn();
                        $('#desc_edit_btn').fadeOut();">Add</a></h5>
                <?php } ?>
              <?php } else { ?>
              <h5><a style="text-decoration: none; color: #555; font-weight: bold;">Description</a></h5>
            <?php } ?>
            <label for="cb3">
              <?php if (!empty($photo_data['photo_desc'])) { ?>
                <?php echo $photo_data['photo_desc']; ?>
              <?php } else { ?>
                <span style="color: #CCC;">No description !</span>
              <?php } ?>
              <?php if (($photo_data['user_id'] == $this->current_user['user_id']) || ($this->is_admin)) { ?>
                <div id="desc_form" style="display: none;">
                  <div style="height: 10px;"></div>
                  <form method="post" action="<?php echo site_url('album/photo_description'); ?>">
                    <input type="hidden" name="photo_id" value="<?php echo $photo_data['photo_id']; ?>" />
                    <textarea maxlength="250" id="photo_description" name="photo_description" style="width: 100%" placeholder="Enter photo description (250)"><?php echo $photo_data['photo_desc']; ?></textarea>
                    <input type="submit" class="btn" value="Save" onclick="return validate_description();"/>
                    <input type="submit" class="btn" value="Cancel" onclick="javascript: $('#desc_form').fadeOut();
                          $('#desc_edit_btn').fadeIn();
                          return false;"/>
                  </form>
                </div>
              <?php } ?>
            </label>
          </div>
        </div>
        <div class="span9">
          <div class="widget" style="text-align: center;">
            <img src="<?php echo base_url('assets/albums/' . $photo_data['album_id'] . '/' . $photo_data['photo_file']); ?>" />
          </div>
          <p class="pull-right">
            <a style="text-decoration: none; cursor: pointer; color: salmon;" href="#photo_<?php echo $photo_data['photo_id']; ?>">&nbsp;&nbsp;#PO<?php echo $photo_data['photo_id']; ?></a>
          </p>
          <span style="float: right; margin-right: 10px;">
            <?php if ($get_user_like_status['status'] == 'yes') { ?>
              <a title="Unlike" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="like_button_photo_<?php echo $photo_data['photo_id']; ?>" onclick="return do_like_action('photo', '<?php echo $photo_data['photo_id']; ?>', '0');"><i class="icon-large icon-thumbs-down"></i></a>
            <?php } else { ?>
              <a title="Like" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="like_button_photo_<?php echo $photo_data['photo_id']; ?>" onclick="return do_like_action('photo', '<?php echo $photo_data['photo_id']; ?>', '1');"><i class="icon-large icon-thumbs-up"></i></a>
            <?php } ?>
          </span>
          <a class="update_like_count" title="Show users who like this" onclick="return show_liked_users('photo', '<?php echo $photo_data['photo_id']; ?>');" style="text-decoration: none; color: #777; float: right; margin-right: 10px; cursor: pointer;" id="like_count_photo_<?php echo $photo_data['photo_id']; ?>"><?php echo $get_user_like_status['total_count']; ?> Likes</a>
          <!-- Comments Section start -->
          <h4>Comments (<span id="total_comments_count"><?php echo $total_comments_count; ?></span>)<img id="loading_anim_blue" style="margin-left: 10px; margin-top: -5px; display: none;" src="<?php echo base_url('assets/img/loading_animation.gif'); ?>"/></h4>
          <div class="header"></div>
          <div class="messages">
            <div class="message">
              <a href="<?php echo base_url('profile/' . $this->current_user['user_name']); ?>"><img title="<?php echo $this->current_user['user_display_name']; ?>" src="<?php echo base_url('assets/photos/' . $this->current_user['user_image']); ?>" class="img-rounded pull-left" style="max-height: 60px; max-width: 60px;"/></a>
              <div class="message-body">
                <input type="hidden" name="csrf_token" value="<?php echo set_csrf_token(); ?>"/>
                <input type="hidden" id="comment_type" name="comment_type" value="<?php echo $comment_type; ?>" />
                <input type="hidden" id="comment_type_id" name="comment_type_id" value="<?php echo $comment_type_id; ?>" />
                <textarea id="comment_message" name="comment_message" placeholder="Enter your comment"></textarea>
                <a class="badge badge-info" id="malayalam_button" style="float: right; cursor: pointer; margin-right: 15px; text-decoration: none;" onclick="return write_malayalam('comment_message');">malaylam</a>
                <input id="post_comment_button" type="button" class="btn" value="Post" onclick="return post_comment('<?php echo $comment_type; ?>', '<?php echo $comment_type_id; ?>');"/>
              </div>
            </div>
            <div id="new_comments"></div>
            <?php $comment_last_id = 0; ?>
            <?php if (!empty($comments_data)) { ?>
              <?php foreach ($comments_data as $comment) { ?>
                <?php $post_id = 'C' . $comment['comment_id']; ?>
                <div class="message" id="comment_<?php echo $comment['comment_id']; ?>">
                  <a href="<?php echo base_url('profile/' . $comment['user_name']); ?>"><img title="<?php echo $comment['user_display_name']; ?>" src="<?php echo base_url('assets/photos/' . $comment['user_image']); ?>" class="img-rounded pull-left" style="max-height: 60px; max-width: 60px;"/></a>
                  <div class="message-body">
                    <p class="pull-right">
                      <a id="<?php echo $post_id; ?>"style="text-decoration: none; cursor: pointer; color: salmon;" href="#<?php echo $post_id; ?>">&nbsp;&nbsp;#<?php echo $post_id; ?></a>
                    </p>
                    <p class="pull-right">&nbsp;(<?php echo time_ago($comment['comment_date']); ?> ago)</p>
                    <p class="pull-right"><a title="Ignore post | <?php echo get_ignore_count('comment', $comment['comment_id']); ?> ignores !" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="ignore_comment_<?php echo $comment['comment_id']; ?>" onclick="return ignore_post('comment', '<?php echo $comment['comment_id']; ?>');"><i class="icon-large icon-flag"></i></a>&nbsp;</p>
                    <?php if (($this->current_user['user_id'] == $comment['user_id']) || ($this->is_admin)) { ?>
                      <a onclick="return delete_comment('<?php echo $comment['comment_id']; ?>');" style="text-decoration: none; cursor: pointer;" >
                        <span style="color: #f8b9b7; float: right; margin-right: 10px;" title="Delete comment"><i class="icon-large icon-trash"></i></span>
                      </a>
                    <?php } ?>
                    <?php if ($this->current_user['user_id'] != $comment['user_id']) { ?>
                      <a onclick="return reply_to_user('comment_message', '<?php echo $comment['user_name']; ?>', '#<?php echo $post_id; ?>');" style="text-decoration: none; cursor: pointer;"><span style="color: skyblue; float: right; margin-right: 10px;" title="Reply to this user"><i class="icon-large icon-retweet"></i></span></a>
                    <?php } ?>
                    <span style="float: right; margin-right: 10px;">
                      <?php $get_user_like_status = get_user_like_status('comment', $comment['comment_id']); ?>
                      <?php if ($get_user_like_status['status'] == 'yes') { ?>
                        <a title="Unlike" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="like_button_comment_<?php echo $comment['comment_id']; ?>" onclick="return do_like_action('comment', '<?php echo $comment['comment_id']; ?>', '0');"><i class="icon-large icon-thumbs-down"></i></a>
                      <?php } else { ?>
                        <a title="Like" style="text-decoration: none; cursor: pointer; color: yellowgreen;" id="like_button_comment_<?php echo $comment['comment_id']; ?>" onclick="return do_like_action('comment', '<?php echo $comment['comment_id']; ?>', '1');"><i class="icon-large icon-thumbs-up"></i></a>
                      <?php } ?>
                    </span>
                    <a class="update_like_count" title="Show users who like this" onclick="return show_liked_users('comment', '<?php echo $comment['comment_id']; ?>');" style="text-decoration: none; color: #777; float: right; margin-right: 10px; cursor: pointer;" id="like_count_comment_<?php echo $comment['comment_id']; ?>"><?php echo $get_user_like_status['total_count']; ?> Likes</a>
                    <h5>
                      <?php echo $comment['user_display_name']; ?>
                      &nbsp;
                      <span style="color: #777; font-size: smaller;">(@<?php echo $comment['user_name']; ?>)</span>
                      &nbsp;
                      <?php if (is_online($comment['user_id'])) { ?>
                        <img src="<?php echo site_url('assets/img/online_button_tiny.png'); ?>" title="Online"/>
                      <?php } else { ?>
                        <img src="<?php echo site_url('assets/img/offline_button_tiny.png'); ?>" title="Offline"/>
                      <?php } ?>
                    </h5>
                    <p style="word-break: normal;"><?php echo nl2br(parse_smileys($comment['comment_message'], base_url('assets/smileys'))); ?></p>
                  </div>
                </div>
              <?php } ?>
              <div id="old_comments"></div>
              <?php $comment_last_id = $comments_data[0]['comment_id']; ?>
              <?php $comment_array_end = end($comments_data); ?>
              <?php $comment_last_loaded_id = $comment_array_end['comment_id']; ?>
              <input type="hidden" id="comment_last_id" value="<?php echo $comment_last_id; ?>" />
              <input type="hidden" id="comment_last_loaded_id" value="<?php echo $comment_last_loaded_id; ?>" />
              <?php if (isset($total_comments_count)) { ?>
                <?php if ($total_comments_count > $comments_limit) { ?>
                  <a id="load_more" style="text-decoration: none; cursor: pointer; float: right; color: black" onclick="return load_old_comments();" title="Load more comments">
                    <img id="loading_animation" src="<?php echo base_url('assets/img/loading_black.gif'); ?>" style="display: none;"/>&nbsp;<b>more</b>&nbsp;<i class="icon-large icon-chevron-down"></i>
                  </a>
                <?php } ?>
              <?php } ?>
              <span style="display: none;" id="no_comments">No comments !</span>
            <?php } else { ?>
              <input type="hidden" id="comment_last_id" value="<?php echo $comment_last_id; ?>" />
              <div class="alert alert-error" id="no_comments">
                <strong>No comments !</strong>
              </div>
            <?php } ?>
          </div>
          <!-- Comments Section end -->
        </div>
      </div>
    </div>
  </div>
</div>
